package cn.edu.scau.cmi.lijiongtao.client;

import cn.edu.scau.cmi.lijiongtao.singleton.*;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.stage.Stage;
import javafx.event.*;

public class SingletonClient extends Application {
	public static void main(String[] args) {
		launch(args);
	}

	@Override
	public void start(Stage primaryStage) throws Exception {
		primaryStage.setTitle("实验二：单例模式");
		primaryStage.setHeight(200);
		primaryStage.setWidth(317);
		
		Button bt1 = new Button("创建毛泽东");
		Button bt2 = new Button("创建江泽明");
		bt1.setMinWidth(150);
		bt2.setMinWidth(150);
		
		HBox hBox = new HBox();
		hBox.getChildren().addAll(bt1,bt2);
		
		Label lb = new Label();
		
		BorderPane bp = new BorderPane();
		bp.setBottom(hBox);
		bp.setCenter(lb);
		
		Scene s = new Scene(bp,480,600);
		primaryStage.setScene(s);
		primaryStage.show();
		
		bt1.setOnAction(new EventHandler<ActionEvent> () {
			@Override
			public void handle(ActionEvent arg0) {
				Chairman ch = Chairman.getInstance("毛泽东");
				lb.setText("主席是" + ch.getName());
			}
		});
		
		bt2.setOnAction(new EventHandler<ActionEvent> () {
			@Override
			public void handle(ActionEvent arg0) {
				Chairman ch = Chairman.getInstance("江泽明");
				lb.setText("主席是" + ch.getName());
			}
		});
	}

}
